#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/8/3 19:37
# @USER    : Shengji He
# @File    : AddStrings.py
# @Software: PyCharm
# @Version  : Python-
# @TASK:


class Solution:
    def addStrings(self, num1: str, num2: str) -> str:
        """
        Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.

        Note:
            - The length of both num1 and num2 is < 5100.
            - Both num1 and num2 contains only digits 0-9.
            - Both num1 and num2 does not contain any leading zero.
            - You must not use any built-in BigInteger library or convert the inputs to integer directly.

        :param num1:
        :param num2:
        :return:
        """
        res = ""
        i, j, carry = len(num1) - 1, len(num2) - 1, 0
        while i >= 0 or j >= 0:
            n1 = int(num1[i]) if i >= 0 else 0
            n2 = int(num2[j]) if j >= 0 else 0
            tmp = n1 + n2 + carry
            carry = tmp // 10
            res = str(tmp % 10) + res
            i, j = i - 1, j - 1
        return "1" + res if carry else res


if __name__ == '__main__':
    print('done')
